from django.core.cache import caches

# 获取缓存对象
from django.http import HttpResponse

cache = caches["default"]

# 创建缓存装饰器
def cache_view(func):
    def _wrapper(request,*args,**kwargs):
        data = cache.get(request.path)
        print("data: ",data)
        if data:
            print("读取缓存中的数据。。。",data)
            return HttpResponse(data)
        print("准备从数据库中读取数据。。。",data)
        response = func(request,*args,**kwargs)
        print("进行缓存数据/设置缓存。。。",response.content)
        cache.set(request.path,response.content)
        return response
    return _wrapper